#pragma once

#include <boostext/smart_ptr.hpp>
#include <boost/property_tree/ptree.hpp>
#include <engine.core/qt_stl_integration.hpp>
#include <engine.core/noncopyable.hpp>

#include "exports.hpp"




/**
 * The DatabaseItem class is the most basic item the DatabaseSystem manages.
 * This class should be subclassed for any type of item. For example, this engine
 * already implements DatabaseMaterial and DatabaseModel, both of which hold the
 * data, necessary to create a Material or Model from it, through the appropriate
 * System.
 */
class ENGINE_DATABASE_API DatabaseItem : public noncopyable
{
public:

	typedef boost::property_tree::path_of<std::string>::type             Path;
	typedef boost::property_tree::basic_ptree<std::string,std::string>   Properties;

protected:

	const QString      m_name;
	const QString      m_inheritance;
	const Properties   m_properties;

public:

	DatabaseItem(const Properties& properties);
	virtual ~DatabaseItem();



	/**
	 * Get the name of this DatabaseItem.
	 * Must be unique amongst all other DatabaseItems.
	 */
	QString name() const;

	/**
	 * Get the name of the DatabaseItem this one inherits.
	 * May be empty.
	 */
	QString inheritance() const;

	/**
	 * Get the type of this DatabaseItem.
	 * Must be unique amongst all other Item types.
	 */
	virtual QString type() const = 0;

	/**
	 * Get all properties of this DatabaseItem.
	 */
	const Properties& properties() const;
};
///////////////////////////////////////////////////////////////////////////////////////////////////

DEFINE_STRICT_PTR(DatabaseItem);

#define IMPLEMENT_DBITEM_FACTORY(class) public: static LOOSE_PTR(DatabaseItem) create(const Properties& data, STRICT_PTR(IDatabaseSystem) database) { return LOOSE_PTR(DatabaseItem)(new class(data, database)); }
